package cn.dai.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author ArkD42
 * @file Rbac
 * @create 2020 - 06 - 11 - 9:22
 */

@WebFilter("/*")
public class EncodingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig){
        System.out.println("- - - - 编码过滤器已启用 - - - -");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        servletRequest.setCharacterEncoding("UTF-8");
        filterChain.doFilter(servletRequest, servletResponse);
        servletResponse.setCharacterEncoding("UTF-8");
        servletResponse.setContentType("text/html;charset=UTF-8");
    }

    @Override
    public void destroy() {
        System.out.println("- - - - 编码过滤器已销毁 - - - -");
    }
}
